package work

import (
	"lnzw/engine/args"
	"lnzw/engine/net/tcp"
	"lnzw/engine/work"

	"google.golang.org/protobuf/proto"
)

type IProtoOther[Req proto.Message, Res proto.Message] interface {
	Handle(conn *tcp.SocketClient, req Req, res Res)
	GetCode() int32
	GetConn() *tcp.SocketClient
	GetRequest() Req
	GetReply() Res
}

type IProtobufNetWork[Req proto.Message, Res proto.Message] interface {
	work.IWork
	IProtoOther[Req, Res]
}

type ProtobufNetWork[Req proto.Message, Res proto.Message] struct {
	conn    *tcp.SocketClient
	request Req
	reply   Res
	code    int32
}

func (p *ProtobufNetWork[Req, Res]) Init(arg *args.Args) {
	p.conn = arg.ReadNext().(*tcp.SocketClient)
	p.code = arg.ReadNext().(int32)
	p.request = arg.ReadNext().(Req)
	p.reply = arg.ReadNext().(Res)
}

func (p *ProtobufNetWork[Req, Res]) GetCode() int32 {
	return p.code
}
func (p *ProtobufNetWork[Req, Res]) GetConn() *tcp.SocketClient {
	return p.conn
}
func (p *ProtobufNetWork[Req, Res]) GetRequest() Req {
	return p.request
}
func (p *ProtobufNetWork[Req, Res]) GetReply() Res {
	return p.reply
}
